﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class OtherControls_DetailViewDemo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            LoadManufacturer();
    
    }

    private void LoadManufacturer()
    {
        SqlDataAdapter da = new SqlDataAdapter("select * from Manufacturer", DataAccess.ConnectionString);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
        //save to file
        ds.WriteXml(Server.MapPath("~/demo.xml"));
    }
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        //get id
        string id = GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
        SqlDataAdapter da = new SqlDataAdapter("select * from Manufacturer where mid=@mid", DataAccess.ConnectionString);
        da.SelectCommand.Parameters.AddWithValue("@mid", id);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DetailsView1.DataSource = ds.Tables[0];
        DetailsView1.DataBind();

        FormView1.DataSource = ds.Tables[0];
        FormView1.DataBind();
    }
}
